# Maintainer: David Runge <dvzrv@archlinux.org>

_name=Nikola
pkgname=nikola
pkgver=8.2.4
pkgrel=3
pkgdesc="A static site and blog generator"
arch=(any)
url="https://getnikola.com/"
license=(MIT)
# still requires python-setuptools due to the use of pkg_resources
depends=(
  python
  python-babel
  python-blinker
  python-doit
  python-dateutil
  python-docutils
  python-logbook
  python-lxml
  python-mako
  python-markdown
  python-natsort
  python-piexif
  python-pillow
  python-pygments
  python-pyrss2gen
  python-requests
  python-setuptools
  python-unidecode
  python-yapsy
)
makedepends=(
  jupyter-notebook
  python-aiohttp
  python-build
  python-ghp-import
  python-husl
  python-installer
  python-ipykernel
  python-jinja
  python-micawber
  python-phpserialize
  python-pygal
  python-pyphen
  python-ruamel-yaml
  python-toml
  python-typogrify
  python-watchdog
  python-wheel
  zeromq
)
checkdepends=(
  libwebp
  python-freezegun
  python-pytest
)
optdepends=(
  'libwebp: for WEBP image file support'
  'jupyter-notebook: for .ipynb support'
  'python-aiohttp: for nikola auto'
  'python-ghp-import: for upload to Github pages'
  'python-hsluv: for section color mixing'
  'python-html5lib: for HTML5 minify and format support'
  'python-husl: for optional color support'
  'python-ipykernel: for .ipynb support'
  'python-jinja: for jinja2 based themes'
  'python-micawber: for embedding media in posts'
  'python-phpserialize: for Wordpress import'
  'python-pygal: for SVG graph plotting'
  'python-pyphen: for hyphenation support'
  'python-ruamel-yaml: for YAML support'
  'python-toml: for TOML support'
  'python-typogrify: for typographical enhancements'
  'python-watchdog: for nikola auto'
)
source=(https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz{,.asc})
sha512sums=('2bcea53181a5371fc1ce7d6d96e5db1ae0ab7c4bc8fe8947ed0d5427e71a469b0f522f1e6f20a47e51a3325730a9646156a8a57bab127785f220c65eb9f891ea'
            'SKIP')
b2sums=('94421a278718fd9ae9f8978854954f2120bab005d10a52294b120d619a67455417eed94bb9e99cc9d01eca4e1d3da210980caef1ad7ff4ca5d25299a39d8eb19'
        'SKIP')
validpgpkeys=('DF32C99CFF84282CF9D4CF7171023DBD5EAAEA16') # Chris Warrick <kwpolska@gmail.com>

prepare() {
  sed -e '/addopts/d' -i $_name-$pkgver/setup.cfg
}

build() {
  cd $_name-$pkgver
  python -m build --wheel --no-isolation

  # shell completions
  python -m $pkgname tabcompletion --shell bash --hardcode-tasks > ${pkgname}_bash
  python -m $pkgname tabcompletion --shell zsh --hardcode-tasks > ${pkgname}_zsh
  # ensure that the shell completion is assigned to the correct executable
  sed -e "s/__main__.py/$pkgname/g" -i "${pkgname}_"{bash,zsh}
}

check() {
  local pytest_options=(
    -vv
  )
  cd $_name-$pkgver
  pytest "${pytest_options[@]}"
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 LICENSE.txt -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 {AUTHORS,CHANGES}.txt {CONTRIBUTING,README}.rst -t "$pkgdir/usr/share/doc/$pkgname/"
  install -vDm 644 ${pkgname}_bash "$pkgdir/usr/share/bash-completion/completions/$pkgname"
  install -vDm 644 ${pkgname}_zsh "$pkgdir/usr/share/zsh/site-functions/_$pkgname"
}
